package karma.main;

import net.minecraft.src.forge.*;
import net.minecraft.client.Minecraft;
import net.minecraft.src.*;

public class ItemHolyBody extends ItemArmor
{
	public static int health = 0;
	public static boolean loaded = false;
    public static int counter = 0;
	public static boolean ELBodyWorn;
	public static int timer = 0;
	

    public ItemHolyBody(int i, EnumArmorMaterial enumarmormaterial, int j, int k)
    {
        super(i, enumarmormaterial, j, k);
    }

    /**
     * Return an item rarity from EnumRarity
     */
    public EnumRarity getRarity(ItemStack itemstack)
    {
        return mod_KarmaCraft.ENCHANTED;
    }
    
    public static void checkIfWorn(Minecraft minecraft)
    {
        if (minecraft.thePlayer.inventory.armorInventory[2] != null && minecraft.thePlayer.inventory.armorInventory[2].getItem() == mod_KarmaCraft.HolyBody)
        {
            doSpecial(minecraft);
        }
    }
    
    public static void doSpecial(Minecraft mc)
    {
    	EntityPlayer player = mc.thePlayer;
    	//do every tick
    	if (health == 0 && !loaded)
    	{
    		health = player.getHealth();
    		loaded = true;
    	}
    	if (timer > 0)
    	{
    		timer --;
    	}
    	if (counter > 0)
    	{
    		counter --;
    	}
    	if (player.getHealth() >= player.getMaxHealth())
    	{
    		timer = 5;
    		counter = 200;
    	}
    	if (health > player.getHealth())//if the player has lost health
		{
			counter = 200;//count 10 seconds 
			health = player.getHealth();
		}
    	
    	//do every 5 ticks
    	if (timer == 0)
    	{
    		if (counter == 0)
    		{
    			player.heal(1);
    			player.inventory.armorInventory[2].damageItem(2, player);
    			//player.addChatMessage("Healed!");
    		}
    		timer = 5;
    	}
    	
    	
    	//testing
    	//player.addChatMessage("Hit counter: " + counter + ", Heal timer: " + timer);

    }
}
